/*** vender ***/
package util;

import java.util.ArrayList;

/** armazena os servidores e portas **/
public class Server {

  private static ArrayList<String> servers = new ArrayList<String>();
  private static int currentServer = 0;
  private static int currentPort;

  public static void addServer(String server) {
    if((server.indexOf(':') == -1) || (servers.contains(server))) return;
    servers.add(0, server);
  }

  public static String[] getServers() {
    if(servers.isEmpty()) return new String[]{"servidores nao cadastrados"};
    return servers.toArray(new String[]{});
  }

  public static String getServer() {
    if(servers.isEmpty()) {
      currentPort = 4444;
      return "127.0.0.1";
    }
    currentServer = (currentServer + 1) % servers.size();
    String[] s = servers.get(currentServer).split(":");
    currentPort = Integer.parseInt(s[1]);
    return s[0];
  }

  public static int getPort() {
    return currentPort;
  }

}
